package test.TP5;

import anaydis.sort.SorterType;
import anaydis.sort.gui.ObservableSorter;
import data.IntegerDataSetGenerator;
import impl.HeapOrderedSorter;
import impl.HeapSorter;
import provider.SorterProviderImpl;
import test.BenchMark;

import java.util.ArrayList;
import java.util.List;

public class ComparatorHeaps {
    public static void main(String[] args) {
        SorterProviderImpl sorters = new SorterProviderImpl();

        HeapSorter heapSorter = (HeapSorter) sorters.getSorterForType(SorterType.HEAP);
        BenchMark benchMark = new BenchMark();
        ((ObservableSorter) heapSorter).addSorterListener(benchMark);

        BenchMark benchMark1 = new BenchMark();
        HeapOrderedSorter heapTernarySorter = (HeapOrderedSorter) sorters.getSorterForType(SorterType.HEAP_TERNARY);
        ((ObservableSorter) heapTernarySorter).addSorterListener(benchMark1);


        IntegerDataSetGenerator generator = new IntegerDataSetGenerator();
        int[] amountOfNumbers = {103, 104, 105, 106};

        List<Integer> listA;
        List<Integer> listB;
        for (int n : amountOfNumbers) {
            System.out.println("**** Lista de " + n + "****");
            listA = generator.createRandom(n);
            listB = new ArrayList<Integer>();
            for (int i = 0; i < listA.size(); i++) {
                listB.add(listA.get(i));
            }

            long time = System.nanoTime();
            heapSorter.sort(generator.getComparator(), listA);
            time = System.nanoTime() - time;
            System.out.println("Heap Sort time :  " + time + " NanoSeg," + " Comparaciones: " + benchMark.getComparisons() + " , Swaps: " + benchMark.getSwaps());

            time = System.nanoTime();
            heapTernarySorter.sort(generator.getComparator(), listB);
            time = System.nanoTime() - time;
            System.out.println("Heap_Ternary Sort time : " + time + " NanoSeg," + " Comparaciones: " + benchMark1.getComparisons() + " , Swaps: " + benchMark1.getSwaps());
            System.out.println("");
        }
    }


}
